# -*- coding: utf-8 -*-

#(c)Jonathan & Gregoire (read __doc__ for more information)
#Copyright (C)%(author)s (%(date)s)
#
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

## @packagename cards
# Cards is the definition of card for play

import sys


__author__      = \
"""
Jonathan MERCIER <bioinfornatics at gmail.com >
Gregoire NAUDIN  <greg.naudin at gmail.com    >

"""
__version__     = "$Revision: 0.1 $"
__date__        = "$Date: 2009/23/09$"
__copyright__   = "Copyright (c) 2009 Jonathan MERCIER and Gregoire NAUDIN"
__license__     = "GPL v3 or under"
__name__        = "Card.py"
__description__ = \
"""
PyCol it is a card game, you can play against human player or computer
PyCol is a french wordplay "picole"
Objective game's is create most structure, the player who close one structure he wins 1 point
The winner is the player with the most points
"""

## Documentation for Card class
# This class is used as an abstract class for a definition of cards
class Card :
    # Class attribute nb_card
    nb_card = 0
    
    ## The contructor
    # This four parameter can take three value: forest, river or plain
    # @param border_up
    # @param border_up_right
    # @param border_up_left
    # @param border_down
    # @param border_down_right
    # @param border_down_left
    # @param border_right
    # @param border_left
    # @param middle
    # @param image
    def __init__(self,border_up_left=None,border_up=None,border_up_right=None,border_left=None,middle=None,border_right=None,border_down_left=None,border_down=None,border_down_right=None,nb_river=None,nb_forest=None,nb_plain=None,image=None):        
        ## Increase class attribute nb_card
        self.__class__.nb_card += 1
        ## Private attribute border_up
        self.__border_up        = border_up
        ## Private attribute border_up_right
        self.__border_up_right  = border_up_right
        ## Private attribute border_up_left
        self.__border_up_left  = border_up_left
        ## Private attribute border_down
        self.__border_down      = border_down
        ## Private attribute border_down_right
        self.__border_down_right  = border_down_right
        ## Private attribute border_down_left
        self.__border_down_left  = border_down_left
        ## Private attribute border_right
        self.__border_right     = border_right
        ## Private attribute border_left
        self.__border_left      = border_left
        ## Private attribute middle
        self.__middle           = middle
        ## Private attribute nb_river
        self.__nb_river         = nb_river
        ## Private attribute nb_forest
        self.__nb_forest        = nb_forest
        ## Private attribute nb_plain
        self.__nb_plain         = nb_plain
        ## Private attribute image
        self.__image            = image 

    
    ## A generic answer for private attribute
    def private(self):
        print "this attribute is read only"
        
    ## Public getter for border_up
    def get_border_up(self):
        return self.__border_up
    
    ## Public getter for border_up_right
    def get_border_up_right(self):
        return self.__border_up_right
    
    ## Public getter for border_up_left
    def get_border_up_left(self):
        return self.__border_up_left
    
    ## Public getter for border_down
    def get_border_down(self):
        return self.__border_down
    
    ## Public getter for border_down_right
    def get_border_down_right(self):
        return self.__border_down_right
    
    ## Public getter for border_down_left
    def get_border_down_left(self):
        return self.__border_down_left

    ## Public getter for border_right
    def get_border_right(self):
        return self.__border_right
    
    ## Public getter for border_left
    def get_border_left(self):
        return self.__border_left
    
    ## Public getter for border_left
    def get_middle(self):
        return self.__middle
    
    ## Public getter for image
    def get_image(self):
        return self.__image
    
    ## Public getter for nb_plain
    def get_nb_plain(self):
        return self.__nb_plain
    ## Private setter for nb_plain
    def set_nb_plain(self,value):
        self.__nb_plain = value
        
    ## Public getter for nb_river
    def get_nb_river(self):
        return self.__nb_river
    ## Private setter for nb_river
    def set_nb_river(self,value):
        self.__nb_river = value
        
        ## Public getter for nb_forest
    def get_nb_forest(self):
        return self.__nb_forest
    ## Private setter for nb_forest
    def set_nb_forest(self,value):
        self.__nb_forest = value
        
    ## Property of border_up attribute
    border_up           = property(get_border_up,private)
    
    ## Property of border_up_right attribute
    border_up_right     = property(get_border_up_right,private)
    
    ## Property of border_up_left attribute
    border_up_left      = property(get_border_up_left,private)

    ## Property of border_down attribute
    border_down         = property(get_border_down,private)

    ## Property of border_down_right attribute
    border_down_right   = property(get_border_down_right,private)

    ## Property of border_down_left attribute
    border_down_left    = property(get_border_down_left,private)
    
    ## Property of border_right attribute
    border_right        = property(get_border_right,private)

    ## Property of border_left attribute
    border_left         = property(get_border_left,private)
    
    ## Property of middle attribute
    middle              =  property(get_middle,private)
    
    ## Property of image attribute
    image               = property(get_image,private)

    ## private method for rotate card
    # @param self  The pointer object
    # @param value The player can rotate the card in different value: 0,  90°, 180°, 270° and -90°, -180°, -270
    def __rotate_value(self,value):
        if value == 0:
            # Do nothing
            pass
        elif value == 90 or value == -270:
            self.__border_up_right,self.__border_right,self.__border_down_right,self.__border_down,self.__border_down_left,self.__border_left,self.__border_up_left,self.__border_up = self.__border_up_left,self.__border_up,self.__border_up_right,self.__border_right,self.__border_down_right,self.__border_down,self.__border_down_left,self.__border_left
        elif value == 180 or value == -180:
            self.__border_up_left,self.__border_up,self.__border_up_right,self.__border_right,self.__border_down_right,self.__border_down,self.__border_down_left,self.__border_left = self.__border_down_right,self.__border_down,self.__border_down_left,self.__border_left,self.__border_up_left,self.__border_up,self.__border_up_right,self.__border_right
        elif value == 270 or value == -90:
            self.__border_down_left,self.__border_left,self.__border_up_left,self.__border_up,self.__border_up_right,self.__border_right,self.__border_down_right,self.__border_down = self.__border_up_left,self.__border_up,self.__border_up_right,self.__border_right,self.__border_down_right,self.__border_down,self.__border_down_left,self.__border_left 
        elif value == 1:
            self.__border_up_left,self.__border_up,self.__border_up_right,self.__border_down_left,self.__border_down,self.__border_down_right = self.__border_down_left,self.__border_down,self.__border_down_right,self.__border_up_left,self.__border_up,self.__border_up_right
        elif value == -1:
            self.__border_up_left,self.__border_left,self.__border_down_left,self.__border_up_right,self.__border_right,self.__border_down_right = self.__border_up_right,self.__border_right,self.__border_down_right,self.__border_up_left,self.__border_left,self.__border_down_left
    
    ## public method for rotate card
    # @param self  The pointer object
    # @param value The player can rotate the card in different value: 0, 90°, 180°, 270° and -90°, -180°, -270°
    def rotate(self,value):
        # check the image
#        try:
#            picture = Image.open(self.__image)
#            ## Rotate image
#            picture.rotate(value)
#        except IOError:
#            print u"Impossible to open file: ",self.__image


        ## Rotate value
        self.__rotate_value(value)
    
